const express = require('express');

const cors = require('cors');


//实例化express对象

const mysql = require('./conn');
const app = express();
// 
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.use(cors());

const upload = require("./router/upload")
const user = require('./router/user');
const admin = require('./router/admin');
const cook = require('./router/cook/cook');
const commodity = require('./router/commodity/commodity');
const message = require('./router/message/message');
app.use('/user',user);
app.use('/admin',admin);
app.use('/upload',upload);
app.use('/cook',cook);
app.use('/commodity',commodity);
app.use('/message',message);

// 将image文件转为静态资源
app.use(express.static('image'));

mysql.connect((err)=>{
    if(err){
        console.log('连接失败',err);
        return err;
    }
    console.log('数据库连接成功');
})

// 定义一个端口号

const port  = 5000;

app.listen(port,()=>{
    console.log(`服务器运行在 http://localhost:${port}`);
})